<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="流程ID，主键" prop="processId">
                        <el-input v-model.number="dataForm.processId" placeholder="流程ID，主键"></el-input>
                </el-form-item>
                <el-form-item label="风险事件ID，关联风险事件表（虽然无外键，但逻辑上关联）" prop="riskEventId">
                        <el-input v-model.number="dataForm.riskEventId" placeholder="风险事件ID，关联风险事件表（虽然无外键，但逻辑上关联）"></el-input>
                </el-form-item>
                <el-form-item label="流程步骤，如识别、评估、处置等" prop="processStep">
                        <el-input v-model="dataForm.processStep" placeholder="流程步骤，如识别、评估、处置等"></el-input>
                </el-form-item>
                <el-form-item label="责任人" prop="responsiblePerson">
                        <el-input v-model="dataForm.responsiblePerson" placeholder="责任人"></el-input>
                </el-form-item>
                <el-form-item label="处理时限" prop="handleTimeLimit">
                        <el-date-picker
                                v-model="dataForm.handleTimeLimit"
                                type="datetime"
                                placeholder="处理时限">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="流程状态" prop="status">
                        <el-input v-model="dataForm.status" placeholder="流程状态"></el-input>
                </el-form-item>
                <el-form-item label="创建时间" prop="createTime">
                        <el-date-picker
                                v-model="dataForm.createTime"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="更新时间" prop="updateTime">
                        <el-date-picker
                                v-model="dataForm.updateTime"
                                type="datetime"
                                placeholder="更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="操作规范，描述该步骤的操作要求" prop="operationNorm">
                        <el-input v-model="dataForm.operationNorm" placeholder="操作规范，描述该步骤的操作要求"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                visible: false,
                dataForm: {
                    processId: null,
                    riskEventId: null,
                    processStep: null,
                    responsiblePerson: null,
                    handleTimeLimit: null,
                    status: null,
                    createTime: null,
                    updateTime: null,
                    operationNorm: null,
                },
                dataRule: {
                    processId: [
                        { required: true, message: '流程ID，主键不能为空', trigger: 'blur' }
                    ],
                    riskEventId: [
                        { required: true, message: '风险事件ID，关联风险事件表（虽然无外键，但逻辑上关联）不能为空', trigger: 'blur' }
                    ],
                    processStep: [
                        { required: true, message: '流程步骤，如识别、评估、处置等不能为空', trigger: 'blur' }
                    ],
                    responsiblePerson: [
                        { required: true, message: '责任人不能为空', trigger: 'blur' }
                    ],
                    handleTimeLimit: [
                        { required: true, message: '处理时限不能为空', trigger: 'blur' }
                    ],
                    status: [
                        { required: true, message: '流程状态不能为空', trigger: 'blur' }
                    ],
                    createTime: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
                    ],
                    updateTime: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
                    ],
                    operationNorm: [
                        { required: true, message: '操作规范，描述该步骤的操作要求不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    this.dataForm.orderId = id || 0
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppRiskDisposalProcess/info/\\$\\{this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm = data.appriskdisposalprocess
                            }
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit () {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppRiskDisposalProcess/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                            method: 'post',
                            data: this.$http.adornData(this.dataForm)
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refreshDataList')
                                    }
                                })
                            } else {
                                this.$message.error(data.msg)
                            }
                        })
                    }
                })
            }
        }
    }
</script>